

 ******************************************************************************
 *																			  *
 *							---	Main Figures ---							  *
 *																			  *
 ******************************************************************************


* Load Data Set

$opendata
$dropvars
$timerestrict

 *----------------------------------------------------------------------------*
 *		--- Figure I Timeline of the Recruitment Process on Hired.com ---     *
 *----------------------------------------------------------------------------*
 
 *	Externally created / not data based

 
 *----------------------------------------------------------------------------*
 *		--- Figure II Interview Request Acceptance Rate and the               *
 *                    Relationship between Ask, Bid and Final Salary ---      *
 *----------------------------------------------------------------------------*

{ 

 * Panel a) Interview request acceptance rate as a function of the bid to ask ratio
{
* Load Data Set

$opendata
$dropvars
$timerestrict

* Create relevant variables
*-----------------------------
	
* Ratio of Bid and Ask salary
	gen ratio_d_s_salary = d_salary / s_salary 
	gen dummy = ratio_d_s_salary == 1


* Restrict Sample to the first five bids received to ensure that the  candidate is 
*active and available for interviews on the platform at the time he or she receives the request
*-----------------------------
keep if s_job_position <= 5

* Define values for scatter
*-----------------------------
recode ratio_d_s_salary (0.6/0.65 = 0.65) (0.65/0.7 = 0.7) (0.7/0.75 = 0.75) ///
						(0.75/0.8 = 0.8) (0.8/0.85 = 0.85) (0.85/0.9 = 0.9) ///
						(0.9/0.95 = 0.95) (0.95/0.999999 = 0.99) (1 = 1)  ///
						(1/1.05 = 1.05) (1.05/1.1 = 1.1) (1.1/1.15 = 1.15) ///
						(1.15/1.2 = 1.2) (1.2/1.25 = 1.25) (1.25/1.3 = 1.3) ///
						(1.3/1.35 = 1.35) (1.35/1.41 = 1.4), gen(auto_bin)

sum d_accept, d
local mean = r(mean)
local display: di %5.2f r(mean)*100

* Create graph on bin level
*-----------------------------
collapse d_accept s_rejection, by (auto_bin dummy female)
label var auto_bin "Ratio of bid to ask salary"
label var d_accept "Share of accepted interview requests"

* Interview request acceptance rate as a function of the bid to ask ratio
twoway (scatter d_accept auto_bin if female == 0, m(Oh) mcolor(navy)) ///
       (scatter d_accept auto_bin if female == 1, m(Sh) mcolor(maroon)),  ///
		ylabel(  0.3 "30%" 0.4 "40%" 0.5 "50%" 0.6 "60%" 0.7 "70%" 0.8 "80%" ) ///
		yscale(r(0.3(0.1)0.8))  ///
		xlabel(0.6 "0.6" 0.8 "0.8" 1 "1" 1.2 "1.2" 1.4 "1.4") ///
		legend(ring(0) pos(10) col(1) region(lstyle(none)) ///
		label(1 "Male") label(2 "Female"))  ///
		yline(.6227, lp(dash) lcolor(black)) ///
		text(.64 0.6 "`display'% of interview requests are accepted", ///
		place(e) size(small)) graphregion(color(white)) bgcolor(white)
graph export "$graphs/figure2a.pdf" , replace 	


}

* Panel b) The relationship between log bid and log ask salary 

{ 
* Load Data Set

$opendata
$dropvars
$timerestrict
	preserve
	binscatter logd_salary logs_salary if (female==1), nquantiles(20) reportreg savedata(female_ask_bin) replace 
	clear
	do female_ask_bin
	save female_ask_bin,replace
	restore

	* Create and Save binscatter for males
	preserve
	binscatter logd_salary logs_salary if (female==0), nquantiles(20) reportreg savedata(male_ask_bin) replace 
	clear
	do male_ask_bin
	save male_ask_bin,replace
	restore

	* Include both saved binscatter
	append using female_ask_bin, gen(female_ask_bin)
	append using male_ask_bin, gen(male_ask_bin)

	*Female Stats
	ivreg2 logd_salary logs_salary if female==1, cluster(jobid sid)
	local beta_f : di %5.3f _b[logs_salary]
	local se_f : di %5.3f _se[logs_salary]
	local cons_f : di %5.3f _b[_cons]
	local se_cons_f : di %5.3f _se[_cons]

	*Male Stats
	ivreg2 logd_salary logs_salary if female==0, cluster(jobid sid)
	local beta_m : di %5.3f _b[logs_salary]
	local se_m : di %5.3f _se[logs_salary]
	local cons_m : di %5.3f _b[_cons]
	local se_cons_m : di %5.3f _se[_cons]

*Create overlayed binscatter graph
twoway lfit logd_salary logs_salary if female_ask_bin == 1 ,sort lp(dash) lc(maroon) /// 
|| scatter logd_salary logs_salary if female_ask_bin == 1 ,  mc(maroon) msymbol(Sh) ///
|| lfit logd_salary logs_salary if male_ask_bin == 1 ,sort lp(solid) lc(navy) /// 
|| scatter logd_salary logs_salary if male_ask_bin == 1 , mc(navy) msymbol(Oh) ///
xtitle("Log Ask salary") ytitle("Log Bid salary") ///
text(12.3 11 `"Female slope = `beta_f' (SE = `se_f')"' ///
`"Female intercept = `cons_f' (SE = `se_cons_f')"' ///
`"Male slope = `beta_m' (SE = `se_m')"' ///
`"Male intercept = `cons_m' (SE = `se_cons_m')"' ///
,  just(left) size(small) box margin(l+2 t+1 b+1) fcolor(white) ) ///
legend(ring(0) pos(4) row(1) region(lstyle(none)) order(2 "Female" 4 "Male" ))

graph export "$graphs/figure2b.pdf", replace

}

* Panel c) The relationship between log final and log bid salary
{
* Load Data Set

$opendata
$dropvars
$timerestrict
	preserve
	binscatter logdf_salary logd_salary if (female==1), nquantiles(20) reportreg savedata(female_bin) replace 
	clear
	do female_bin
	save female_bin,replace
	restore

	* --- Create and Save binscatter for males
	preserve
	binscatter logdf_salary logd_salary if (female==0), nquantiles(20) reportreg savedata(male_bin) replace 
	clear
	do male_bin
	save male_bin,replace
	restore

	* Include both saved binscatter
	append using female_bin, gen(female_bin)
	append using male_bin, gen(male_bin)

	* Female Stats
	ivreg2 logdf_salary logd_salary if female==1, cluster(jobid sid)
	local beta_f : di %5.3f _b[logd_salary]
	local se_f : di %5.3f _se[logd_salary]
	local cons_f : di %5.3f _b[_cons]
	local se_cons_f : di %5.3f _se[_cons]

	* Male Stats
	ivreg2 logdf_salary logd_salary if female==0, cluster(jobid sid)
	local beta_m : di %5.3f _b[logd_salary]
	local se_m : di %5.3f _se[logd_salary]
	local cons_m : di %5.3f _b[_cons]
	local se_cons_m : di %5.3f _se[_cons]

*Create overlayed binscatter graph
twoway lfit logdf_salary logd_salary if female_bin == 1 ,sort lp(dash) lc(maroon) /// 
|| scatter logdf_salary logd_salary if female_bin == 1 , mc(maroon) msymbol(Sh) || ///
lfit logdf_salary logd_salary if male_bin == 1 ,sort lp(solid) lc(navy) /// 
|| scatter logdf_salary logd_salary if male_bin == 1 , mc(navy) msymbol(Oh) ///
xtitle("Log Bid salary") ytitle("Log Final salary") ///
text(12.3 11 `"Female slope = `beta_f' (SE = `se_f')"' ///
`"Female intercept = `cons_f' (SE = `se_cons_f')"' ///
`"Male slope = `beta_m' (SE = `se_m')"' ///
`"Male intercept = `cons_m' (SE = `se_cons_m')"' ///
,  just(left) size(small) box margin(l+2 t+1 b+1) fcolor(white) ) ///
legend(ring(0) pos(4) row(1) region(lstyle(none)) order(2 "Female" 4 "Male" ))

graph export "$graphs/figure2c.pdf", replace


} 
 
}


 *----------------------------------------------------------------------------*
 *	  	--- Figure III Heterogeneity in the Ask and Bid Gap by Experience --- *
 *----------------------------------------------------------------------------*
 
{

 * Panel a) Residual Ask gap - resume characteristics
{  
* Load Data Set

$opendata
$dropvars
$timerestrict

sort sid batch_start_date

collapse (first) female s_salary $ccontrols $fcontrols $preferences smonthyear s_experience logs_salary, by(sid)

forvalues i=0/7{
reg logs_salary i.female  $controls if s_experience == `i', r
estimates store OLS0exp`i'
}

coefplot (OLS0exp0 \ OLS0exp1 \ OLS0exp2 \ OLS0exp3 \ OLS0exp4 \ OLS0exp5 \ ///
		  OLS0exp6 \  OLS0exp7) , ///
		  $plot  ytitle("Ask gap") coeflabels(OLS0exp0= "0-4" OLS0exp1="4-6" ///
		  OLS0exp2= "6-8" OLS0exp3= "8-10" OLS0exp4= "10-12" OLS0exp5= "12-15" ///
		  OLS0exp6= "15-20" OLS0exp7= "20+") graphregion(color(white))
		  
graph export  "$graphs/figure3a.pdf", replace as(pdf)

} 

 * Panel b) Residual Bid gap - resume characteristics
{
* Load Data Set

$opendata
$dropvars
$timerestrict

forvalues i=0/7{
ivreg2 logd_salary i.female $controls if s_experience == `i', cluster(jobid sid)
estimates store OLS1exp`i'
}

coefplot (OLS1exp0 \ OLS1exp1 \ OLS1exp2 \ OLS1exp3 \ OLS1exp4 \ OLS1exp5 \ ///
		  OLS1exp6 \ OLS1exp7), ///
		  $plot ytitle ("Bid gap")  coeflabels(OLS1exp0= "0-4" OLS1exp1="4-6" ///
		  OLS1exp2= "6-8" OLS1exp3= "8-10" OLS1exp4= "10-12" OLS1exp5= "12-15" ///
		  OLS1exp6= "15-20" OLS1exp7= "20+") graphregion(color(white))
graph export  "$graphs/figure3b.pdf", replace as(pdf)


}

 * Panel c) Residual Bid gap - resume characteristics + ask salary
{
* Load Data Set

$opendata
$dropvars
$timerestrict

forvalues i=0/7{
ivreg2 logd_salary i.female logs_salary $controls if s_experience == `i', cluster(jobid sid)
estimates store OLS1exp_s_`i'
}

coefplot (OLS1exp_s_0 \ OLS1exp_s_1 \ OLS1exp_s_2 \ OLS1exp_s_3 \ OLS1exp_s_4 \ ///
		  OLS1exp_s_5 \ OLS1exp_s_6 \  OLS1exp_s_7), ///
		  $plot ytitle ("Bid gap, controlling for ask") coeflabels(OLS1exp_s_0= "0-4" ///
		  OLS1exp_s_1="4-6" OLS1exp_s_2= "6-8" OLS1exp_s_3= "8-10" OLS1exp_s_4= "10-12" ///
		  OLS1exp_s_5= "12-15" OLS1exp_s_6= "15-20" OLS1exp_s_7= "20+") graphregion(color(white))
		  
graph export  "$graphs/figure3c.pdf", replace as(pdf)


}

}


 *----------------------------------------------------------------------------*
 *		--- Figure IV Effect of the Reform on the Gender Ask and Bid Gaps --- *
 *----------------------------------------------------------------------------*

{

* Load Data Set
* no longer restrict to pre-period
$opendata
$dropvars
* SF software engineers
keep if s_primary_field == 4 & s_choice_location == 1


foreach l in    "s" "d" "df" {	
			if "`l'" == "d" local variable  "Bid" 
			if "`l'" == "s" local variable  "Ask"  
			if "`l'" == "df" local variable  "Final"  

preserve
* SF software engineers
gen resid  = .
		forvalues d=695(1)713 {
			if "`l'" == "d"{
			reg log`l'_salary i.female $ccontrols i.(${fcontrols}) i.(${preferences})  if smonthyear== `d' , r
						}
			if "`l'" == "s"{
			reg log`l'_salary i.female $ccontrols i.(${fcontrols}) i.(${preferences})   if smonthyear== `d' , r
						}	
			if "`l'" == "df"{
			reg log`l'_salary i.female $ccontrols i.(${fcontrols}) i.(${preferences})   if smonthyear== `d' , r
						}	
			predict tempresid, r
			replace tempresid = tempresid + _b[1.female]*female if smonthyear== `d'
			quietly sum log`l'_salary  if smonthyear== `d'
			global origmean=r(mean)
			quietly sum tempresid  if smonthyear== `d'
			replace tempresid = tempresid + ($origmean-r(mean)) if smonthyear== `d'
			replace resid = tempresid if smonthyear== `d'
			drop tempresid
			save "$data/monthbymonth_`l'_salary_c.dta", replace
				}


use "$data/monthbymonth_`l'_salary_c.dta", clear
							
capture collapse (mean) resid  , by(female smonthyear)
 keep if !mi(resid) & female != 2
 reshape wide resid , i(smonthyear) j(female)
 gen months_from_change =smonthyear-704
 
 twoway (connected resid0 months_from_change, m(Oh) lpattern(solid )) (connected resid1 months_from_change, m(Sh) lpattern(dash )), ///
		 xline(-0.5, lpattern(solid ) lcolor(red)) ///
		xtitle("Months to change", margin(small)) ///
		xscale(r(-4(1)4)) ///
		xlabel(-8 "-8"  -6 "-6" -4 "-4"  -2 "-2" 0 "0"  2 "2" 4 "4" 6 "6" 8 "8") ///
		yscale(r(11.82(0.02)11.96)) ///
		ylabel( 11.82 "11.82"  11.84 "11.84" 11.86 "11.86" 11.88 "11.88" 11.90 "11.90" 11.92 "11.92" 11.94 "11.94" 11.96 "11.96") ///  
		ytitle("Log `variable' salary") ///
		legend(ring(0) pos(10) col(1) lab(1 "Male") lab(2 "Female"))

 * Panel a) Log ask salary - all resume controls
 if "`l'" == "s"{
graph export "$graphs/figure4a.pdf", replace
 }
 * Panel b) Log bid salary - all resume controls
  if "`l'" == "d"{
graph export "$graphs/figure4b.pdf", replace
 }
  * Panel c) Log final salary - all resume controls
   if "`l'" == "df"{
graph export "$graphs/figure4c.pdf", replace
 }
 
restore
 }
 

}

 
 *----------------------------------------------------------------------------*
 *	  	--- Figure V Cumulative Distribution Function of Candidates' 		  *
 *					 Ask Salaries before and after the Reform ---  			  *
 *----------------------------------------------------------------------------*
 
{
* Load Data Set
* no longer restrict to pre-period
$opendata
$dropvars
* SF software engineers
keep if s_primary_field == 4 & s_choice_location == 1
* before period is limited to 12 months for better comparability of ask salaries
keep if smonthyear >= 692
keep if female != 2
 * Panel a) and b) : Distribution of Ask Salaries by Gender
	forvalues j=0(1)1 { 
		label var s_salary "Ask salary of SF software engineers"
		cdfplot  s_salary if after == `j' & s_salary < 300000, by(female) opt1(legend(ring(0) pos(10) col(1) lab(1 "Male") lab(2 "Female")) )
			
		if `j' == 0 {
			graph export "$graphs/figure5a.pdf", replace
		}	
		if `j' == 1 {
			graph export "$graphs/figure5b.pdf", replace
		}	
	}
 * Panel c) and d) : Distribution of Ask Salaries by Gender and experience group
 local h  "Male "
 sum d_salary if  s_primary_field_exp == 2, d
	local mediansal = r(p50)
	forvalues j=0(1)1 { 
		label var s_salary "`h'Ask salary of SF software engineers with 4-6 years of experience "
		cdfplot  s_salary if female == `j' & s_primary_field_exp == 2 & s_salary < 300000, by(after) opt1(legend(ring(0) pos(10) col(1) lab(1 "before") lab(2 "after")) lcolor(green black) lp(solid dash) ) xline(`mediansal')
		
		if `j' == 0 {
			graph export "$graphs/figure5c.pdf", replace
		}	
		if `j' == 1 {
			graph export "$graphs/figure5d.pdf", replace
		}	
		    local h  "Female " 
	}
	

}	

 
 *----------------------------------------------------------------------------*
 *	  	--- Figure VI The Effect of the Reform on the Bid and Ask Gap		  *
 *					  as a Function of the Pre-Reform Gaps ---         		  *
 *----------------------------------------------------------------------------*
 
 
{
* Load Data Set
* no longer restrict to pre-period
$opendata
$dropvars
* SF software engineers
keep if s_primary_field == 4 & s_choice_location == 1


* This calls data created in the Main_Tables.do
use "$data/eventstudy_experience.dta", clear 
gen group = string(experience) + salary
replace var  = "female" if var == "1.female"
replace var  = "femaleafter" if var == "1.female_after"
ren var female
reshape wide coef stderr ci_lower ci_upper N r2  , i(group) j(female) string
label define exp -1 "All" 0 "0-4" 1 "4-10" 2 "10+"
label value experience exp
replace coeffemale = - coeffemale
	
twoway (scatter coeffemaleafter coeffemale  if salary == "ws_salary", mlabel(experience) mlabp(12) ) ///
(scatter coeffemaleafter coeffemale  if salary == "d_salary",  mlabel(experience) mlabp(6)) ///
(function y=x, range(0 0.05)), yscale(range(0 0.05)) xscale(range(0 0.05))   ///
legend(ring(0) pos(10) col(1) lab(1 "Ask") lab(2 "Bid") lab(3 "45 degree line")) ///
xtitle("(-) Pre-reform gap") ytitle("Effect of the reform on the gap") ///
xlabel( 0 "0%" 0.01 "1%" 0.02 "2%" 0.03 "3%" 0.04 "4%" 0.05 "5%") ///
ylabel( 0 "0%" 0.01 "1%" 0.02 "2%" 0.03 "3%" 0.04 "4%" 0.05 "5%")
		  
graph export  "$graphs/figure6.pdf", replace 

}
 
 
 *----------------------------------------------------------------------------*
 *	  	--- Figure VII Estimates of the Effect of the Reform-Induced Change	  *
 *					   in Asks on the Bids ---         		 				  *
 *----------------------------------------------------------------------------*
 
 
{
* Load Data Set
* no longer restrict to pre-period
$opendata
$dropvars
* SF software engineers
keep if s_primary_field == 4 & s_choice_location == 1

* separate first stage
gen first_stage = .
forvalues e=0(1)2  {
forvalues f=0(1)1 {
reg logs_salary i.exp_group##i.after##i.female $expcontrols  if exp_group  == `e' & female == `f' & !mi(d_salary), vce(cluster sid)
replace first_stage = _b[1.after] if exp_group  == `e' & female == `f'
}
}

gen reduced_form = .
gen stde = .

forvalues e=0(1)2  {
forvalues f=0(1)1 {
ivreg2 logd_salary i.exp_group##i.after##i.female $expcontrols if exp_group  == `e' & female == `f', cluster (sid jobid) 
replace reduced = _b[1.after] if exp_group  == `e' & female == `f'
replace stde = _se[1.after] if exp_group  == `e' & female == `f'
}
}

bys exp_group female: gen nbobs = _N
gen yu = reduced + 1.96*stde
gen yl = reduced - 1.96*stde

gen groups = "F 0-4" if exp_group == 0 & female == 1
replace groups = "M 0-4" if exp_group == 0 & female == 0
replace groups = "F 4-10" if exp_group == 1 & female == 1
replace groups = "M 4-10" if exp_group == 1 & female == 0
replace groups = "F 10+" if exp_group == 2 & female == 1
replace groups = "M 10+" if exp_group == 2 & female == 0

preserve
bys exp_group female : keep if _n == 1
reg reduced first_stage [aw=nbobs] , nocons
local y_line = _b[first_stage]
restore

gen liner = `y_line' * first_stage

twoway (line liner first_stage , lcolor(black) lpattern(solid dash)) ///
	   (scatter reduced first_stage, msymbol(square) mlabposition(5) mcolor(black) mlabel(groups)) ///
	   (rcap yu  yl first_stage, lcolor(gray) ), ///
	   leg(off) xtitle("First Stage Effect on Log Ask")  yscale(r(-0.04 .1)) xscale(r(-0.01 .04)) ///
	   ylabel( -.04 "-.04" -.03 "-.03" -.02 "-.02" -.01 "-.01" 0 "0" .01 ".01"  .02 ".02"  .03 ".03"  0.04 ".04"  0.05 ".05" 0.06 ".06" 0.07 ".07"  0.08 ".08" 0.09 ".09"  0.1 ".1"  )  ///
	   	   xlabel( -.01 "-.01" 0 "0" .01 ".01"  .02 ".02"  .03 ".03"  0.04 ".04"   )  ///
	   ytitle("Reduced Form Effect on Log Bid") graphregion(margin(l+1 r+3)) text(.085 -.005  "Weighted Slope = 0.91", size(small)) 

graph export "$graphs/figure7.png", replace

}


 
 